Fractional Decimal to Binary Converter

(and Back Again)


This calculator converts numbers from base ten to binary and back using a simple algorithm. It works for both intergers and decimals. Precision of the output can be modified as desired.

Never realized how many meanings "decimal" has (and are used here): "decimal" or Base 10 number system, the "decimal" digits to the right of the "period", and decimal point for the "period".

For Base 10 to Base 2 integer conversion the algorithm is simply successive divisions by 2. The fractional part is converted by successive multiplications of resulting fractional parts by 2. For Base 2 to Base 10 integer conversion the algorithm multiplies the individual digits by increasing powers of 2 and for the decimal part the individual digits are multiplied by the reciprocals of increasing powers of 2.

For the integer part of base ten numbers JavaScript provides a simple way to convert to binary with number.toString(2), e.g., if integer = 29, then integer.toString(2) returns 11101.

To use the calculator enter a number, specify whether the number is in Base 10 or Base 2, and the desired precision. The default is Base 10 and ten digits of precision after the decimal point. Ten or eleven Base 2 decimals of precision is equivalent to "thousandths" precision in Base 10.




Enter a number and hit the button:








A lot of precision can be required to get a base ten fraction back from its base two equivalent. For example, 3.1415 with a precision of 20 when converted to binary (11.00100100001110010101) and the binary answer pasted back into "Number to Convert" returned: 3.14149951934814453125.